// time: 2021.4.14
// by: 陈同学

#include<iostream>
#include<string>
using namespace std;
struct node
{
    string name;
    int score;
    node* next;
};
node* readList(); // 读取用户输入的数据
node* deleteNode(node* head); // 删除分数低于60
void showList(node* head);  // 打印分数
void sortList(node* head);  // 排序
int main()
{
    node* head=readList();
    showList(head);
    cout<<"Delete student who score is lower than 60:"<<endl;
    head=deleteNode(head);
    showList(head);
    sortList(head);
    showList(head);
}
// 读取用户输入的数据
node* readList()
{
    node* head=new node;
    node* p=new node;
    head=p;
    p->next=NULL;
    int count=1;
    while (true)
    {
        cout<<"Please enter the "<<count<<" student name:";
        string name;
        cin>>p->name;
        cout<<"Please enter student score: ";
        int score;
        cin>>p->score;
        if (p->score <0)
        {
            break;
        }
        node* pr=new node;
        pr->next=NULL;
        p->next=pr;
        p=pr;
        count++;
    }
    return head;
}
// 删除分数低于60
node* deleteNode(node* head)
{
    node* p=new node;
    p=head;
    while (p->next != NULL)
    {
        if (p->score < 60)
        {
            node* pr=new node;
            pr=p;
            p=p->next;
            delete pr;
        }    
    }
    return head;
}
// 打印分数
void showList(node* head)
{
    node* p=new node;
    p=head;
    while (p->next !=NULL)
    {
        cout<<"name: "<<p->name<<"  score: "<<p->score<<endl;
        p=p->next;
    }
    
}
// 排序
void sortList(node* head)
{
    node* p= new node;
    node* q=new node;
    p=head->next;
    q=p->next;
    while (q!=NULL)
    {
        head->score=q->score;
        while (p!=q)
        {
            if (p->score <= head->score)
            {
                p=p->next;
            }
            else
            {
                swap(p->score,q->score);
                p=p->next;
            
            }
        }
        q=q->next;
        p=head->next;
    }   
}